package com.example.demo.common;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author :蕉绿
 * @Date : 2023/3/10 20:46
 * @Version : V1.0
 * @Description :
 */

//同一数据格式返回  code msg  data
@Data
public class AjaxResult implements Serializable {


    //状态码
    private Integer code;
    //状态码描述信息
    private String msg;
    //返回到数据
    private Object data;

    //两个方法  操作返回的结果

    public static AjaxResult success(Object data){

        AjaxResult result = new AjaxResult();
        result.setCode(200);
        result.setMsg("");
        result.setData(data);

        return result;
    }
    public static AjaxResult success(int code,Object data){

        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setMsg("");
        result.setData(data);

        return result;
    }
    public static AjaxResult success(int code,String msg,Object data){

        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);

        return result;
    }

    public static AjaxResult fail(int code,String msg) {
        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }
    public static AjaxResult fail(int code,String msg,int data) {
        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

}
